package com.clps.cn;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;

import java.io.InputStream;
import java.util.zip.ZipInputStream;

public class ActiviteDevelopment {
    public static void main(String[] args) {
        //01创建ProcressEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        //02得到RepositoryService实例
        RepositoryService repositoryService = processEngine.getRepositoryService();

        //03：进行部署
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("diagram/holiday.bpmn")
                .addClasspathResource("diagram/holiday.png")
                .name("填写请假单")
                .deploy();


        //输出部署到某一个位置
        System.out.println("deployment.getName() = " + deployment.getName());
        System.out.println("deployment.getId() = " + deployment.getId());

    }

    /**
     * 因为流程部署的时候要上传服务器，zip更好上传。
     */
    @Test
    public void testZip() {
        //01创建ProcressEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        //02得到RepositoryService实例
        RepositoryService repositoryService = processEngine.getRepositoryService();

        //03转换成zipinputStream流对象
        InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("diagram/diagram.zip");

        //04讲inputStranm流，转换成zipInputStream流
        ZipInputStream zipInputStream = new ZipInputStream(resourceAsStream);

        //05进行部署
        Deployment deployment = repositoryService.createDeployment()
                .addZipInputStream(zipInputStream)
                .name("请假审批单流程")
                .deploy();

        //输出部署的一些信息
        System.out.println("deployment.getName() = " + deployment.getName());
        System.out.println("deployment.getId() = " + deployment.getId());

    }

}


